package com.polymer.app.service.repository.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.polymer.app.entity.BussinessDO;
import com.polymer.app.entity.InstitutionDO;
import com.polymer.app.mapper.BussinessMapper;
import com.polymer.app.mapper.InstitutionMapper;
import com.polymer.app.service.repository.BussinessRepository;
import com.polymer.app.utils.LoggerUtil;
import com.polymer.app.utils.ObjectSizeFetcher;

@Service
public class BussinissRepositoryImpl implements BussinessRepository {
    private static final  Logger logger=Logger.getLogger(BussinissRepositoryImpl.class);
    
    @Autowired
    private BussinessMapper mapper;
    
    @Autowired
    private InstitutionMapper institutionMapper;

    @Override
    public BussinessDO getbus(String id) {
        return mapper.selectByPrimaryKey(id);
    }
    
    @Override
    public BussinessDO getbusNoXML(String id) {
        return mapper.selectByPrimaryKeyNoXML(id);
    }

    @Override
    public int saveBus(BussinessDO bussinessDO) {
        return mapper.insert(bussinessDO);
    }
    
    @Override
    public List<InstitutionDO> selectPByCityCodeAndinsCodeAndType(String cityCode, String insCode, String organType, long startRow, long endRow,
            double longitude, double latitude, int val) {
        List<InstitutionDO> result = null;
        try {
            LoggerUtil.info(
                    logger,
                    "从db获取获取neworgan药店列表，参数={0}|{1}|{2}|{3}---longitude:{4},latitude:{5},val:{6}",
                    cityCode,
                    organType,
                    startRow,
                    endRow,
                    longitude,
                    latitude,
                    val);
            result = institutionMapper.selectByPCityCodeAndinsCodeAndType(cityCode, insCode, organType, startRow, endRow, longitude, latitude, val);
            LoggerUtil.info(logger, "从db获取药店展台列表， 出参={0}", result);

        } catch (Exception e) {
            LoggerUtil.warn(e, logger, "获取organ药店列表系统异常，参数={0}|{1}|{2}|{3}", cityCode, organType, startRow, endRow);
        }
        return result;
    }
    
    public static void main(String[] args) {
        List<InstitutionDO> result = new ArrayList<InstitutionDO>();
        InstitutionDO ido=new InstitutionDO();
        for (int i = 0; i < 10000000; i++) {
            ido=new InstitutionDO();
            result.add(ido); 
        }
        System.out.println(result.size());
        System.out.println(ObjectSizeFetcher.sizeOf(result));
    }
}
